package org.example.io.protocol.command;

import io.netty.channel.Channel;
import org.example.io.protocol.packet.LoginRequestPacket;
import org.example.io.util.LogUtil;

import java.util.Scanner;
import java.util.UUID;

public class LoginCommand implements ConsoleCommand{

    @Override
    public void exec(Scanner scanner, Channel channel) {
        LogUtil.info("请输入用户名：");
        String username = scanner.next();
        LogUtil.info("请输入密码：");
        String password = scanner.next();

        LoginRequestPacket packet = new LoginRequestPacket();
        packet.setUserName(username);
        packet.setPassword(password);
        packet.setUserId(UUID.randomUUID().toString());
        channel.writeAndFlush(packet);

        // 确保登录成功
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String commandType() {
        return "login";
    }
}
